<!DOCTYPE html>
<html>
<head>
<title>apidoc.js-好用方便的API文档生成工具</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) */
/* Author: Nicolas Hery - http://nicolashery.com */
/* Version: b13fe65ca28d2e568c6ed5d7f06581183df8f2ff */
/* Source: https://github.com/nicolahery/markdownpad-github */

/* RESET
=============================================================================*/

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
}

/* BODY
=============================================================================*/

body {
  font-family: Helvetica, arial, freesans, clean, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #333;
  background-color: #fff;
  padding: 20px;
  max-width: 960px;
  margin: 0 auto;
}

body>*:first-child {
  margin-top: 0 !important;
}

body>*:last-child {
  margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
  margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
  margin: 20px 0 10px;
  padding: 0;
  font-weight: bold;
  -webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
  font-size: inherit;
}

h1 {
  font-size: 28px;
  color: #000;
}

h2 {
  font-size: 24px;
  border-bottom: 1px solid #ccc;
  color: #000;
}

h3 {
  font-size: 18px;
}

h4 {
  font-size: 16px;
}

h5 {
  font-size: 14px;
}

h6 {
  color: #777;
  font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
  margin-top: 0;
  padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
  margin-top: 0;
  padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
  margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
  color: #4183C4;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
  padding-left: 30px;
}

ul li > :first-child, 
ol li > :first-child, 
ul li ul:first-of-type, 
ol li ol:first-of-type, 
ul li ol:first-of-type, 
ol li ul:first-of-type {
  margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
  margin-bottom: 0;
}

dl {
  padding: 0;
}

dl dt {
  font-size: 14px;
  font-weight: bold;
  font-style: italic;
  padding: 0;
  margin: 15px 0 5px;
}

dl dt:first-child {
  padding: 0;
}

dl dt>:first-child {
  margin-top: 0px;
}

dl dt>:last-child {
  margin-bottom: 0px;
}

dl dd {
  margin: 0 0 15px;
  padding: 0 15px;
}

dl dd>:first-child {
  margin-top: 0px;
}

dl dd>:last-child {
  margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
  font-size: 12px;
  font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
  margin: 0 0px;
  padding: 0px 0px;
  white-space: nowrap;
  border: 1px solid #eaeaea;
  background-color: #f8f8f8;
  border-radius: 3px;
}

pre>code {
  margin: 0;
  padding: 0;
  white-space: pre;
  border: none;
  background: transparent;
}

pre {
  background-color: #f8f8f8;
  border: 1px solid #ccc;
  font-size: 13px;
  line-height: 19px;
  overflow: auto;
  padding: 6px 10px;
  border-radius: 3px;
}

pre code, pre tt {
  background-color: transparent;
  border: none;
}

kbd {
    -moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    background-color: #DDDDDD;
    background-image: linear-gradient(#F1F1F1, #DDDDDD);
    background-repeat: repeat-x;
    border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
    border-image: none;
    border-radius: 2px 2px 2px 2px;
    border-style: solid;
    border-width: 1px;
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    line-height: 10px;
    padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
  border-left: 4px solid #DDD;
  padding: 0 15px;
  color: #777;
}

blockquote>:first-child {
  margin-top: 0px;
}

blockquote>:last-child {
  margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
  clear: both;
  margin: 15px 0;
  height: 0px;
  overflow: hidden;
  border: none;
  background: transparent;
  border-bottom: 4px solid #ddd;
  padding: 0;
}

/* TABLES
=============================================================================*/

table th {
  font-weight: bold;
}

table th, table td {
  border: 1px solid #ccc;
  padding: 6px 13px;
}

table tr {
  border-top: 1px solid #ccc;
  background-color: #fff;
}

table tr:nth-child(2n) {
  background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
  max-width: 100%
}
</style>
</head>
<body>
<h1>apidoc.js-API文档生成工具</h1>
<hr>
<h2>1.介绍：</h2>
<p>1.apidoc是根据源代码中的代码注释生成的WEB API文档。</p>
<p>2.支持大部分主流语言java、javascript、c#、php、python等。</p>
<p>3.支持api版本的版本更新，可查看比较不同版本的api。</p>
<p>4.可在web页面进行接口测试。</p>
<p>注释示例：</p>
<h4>Java、JavaScript、PHP 、C #</h4>
<pre><code>/**
 * @api {get} /user/:id Request User information
 * @apiName GetUser
 * @apiGroup User
 *
 * @apiParam {Number} id Users unique ID.
 *
 * @apiSuccess {String} firstname Firstname of the User.
 * @apiSuccess {String} lastname  Lastname of the User.
 */
</code></pre>

<h4>Python</h4>
<pre><code>&quot;&quot;&quot;
@api {get} /user/:id Request User information
@apiName GetUser
@apiGroup User
@apiParam {Number} id Users unique ID.
@apiSuccess {String} firstname Firstname of the User.
@apiSuccess {String} lastname  Lastname of the User.
&quot;&quot;&quot;
</code></pre>

<h2>2.安装</h2>
<p>apidoc是基于nodeJs平台，在安装apidoc之前，需要先安装nodeJs。</p>
<h4>nodeJs安装</h4>
<p>首先，去node.js官网上下载最新的安装包，下载自己对应系统的安装包,常规步骤安装，配置node环境变量。（网上有教程）</p>
<p><img src="img/1.png" /></p>
<h4>apidoc安装</h4>
<p>1 . 在命令行中输入 npm install apidoc -g  进行安装</p>
<p><img src="img/2.png" /></p>
<p>2 . 一段时间后，出现下图信息，则apidoc安装成功。</p>
<p><img src="img/3.png" /></p>
<p>3 . 输入 apidoc -v 命令，如果出现下图信息，则安装成功</p>
<p><img src="img/4.png" /></p>
<h2>3.源代码注入注释</h2>
<h3>3.1 注释示例</h3>
<pre><code>/**
 * @apiDefine Channel 1.2 FM对讲频道信息接口
 */
/**
 * @apiDefine ChannelDto
 * @apiSuccess {string} channelId 对讲频道ID，唯一标识一个频道的编号
 * @apiSuccess {string} channelName 对讲频道名称
 * @apiSuccess {number{number(6,4)}} hertz 对讲频道hertz
 * @apiSuccess {string} description 备注，允许为空
 */
/**
 * @api {get} /channel/{id} 1.2.2.根据频道ID查询对讲频道
 * @apiVersion 0.1.0
 * @apiGroup Channel
 * @apiDescription 根据频道ID查询对讲频道
 * 
 * @apiParam {string} id 对讲频道ID，唯一标识一个频道的编号
 * 
 * @apiSuccessExample {json} 成功的响应: HTTP 200 OK
 *                    {&quot;state&quot;:0,&quot;value&quot;:{&quot;channelId&quot;:&quot;channel_1&quot;,&quot;channelName&quot;:&quot;华微软件频道一&quot;,&quot;hertz&quot;:90.3456,&quot;description&quot;:&quot;&quot;}}
 * @apiUse ChannelDto
 */
</code></pre>

<hr>
<h3>3.2 逐一解释上面的注释</h3>
<h4>3.2.1 @api</h4>
<pre><code>@api {method} path [title]
</code></pre>

<table>
<thead>
<tr>
	<th align="center">名称</th>
	<th align="center">含义</th>
</tr>
</thead>
<tbody>
<tr>
	<td align="center">method</td>
	<td align="center">请求方法的名称DELETE, GET, POST, PUT</td>
</tr>
<tr>
	<td align="center">path</td>
	<td align="center">请求的路径</td>
</tr>
<tr>
	<td align="center">title</td>
	<td align="center">title</td>
</tr>
</tbody>
</table>
<h4>3.2.2  @apiDefine 自定义api属性模板</h4>
<p>格式：</p>
<pre><code>@apiDefine name [title] [description]
</code></pre>

<p>可以自定义@apiPermission ，@apiSuccess或者其他属性，不同api都可以使用，这里定义了模块名Channel 和 model对象的字段集合，供不同api重复使用。</p>
<p>引用方式：@apiUse ChannelDto</p>
<h3>3.2.3 @apiVersion 版本</h3>
<p>一个API可能有不同的版本，添加这个属性可以根据版本来显示对应的API。</p>
<pre><code>/**
 * @api {get} /channel/{id} 1.2.2.根据频道ID查询对讲频道
 * @apiVersion 0.1.0
 * /
/**
 * @api {get} /channel/{id} 1.2.2.根据频道ID查询对讲频道
 * @apiVersion 0.2.0
 * /
public String login() {
    return &quot;success&quot;;
}
</code></pre>

<p>一段apidoc注释对应一个api接口，若如上图login接口源码中有2段apidoc注释，分别对应0.1.0和0.2.0版本，那么生成的文档才有2个版本的对比，下图为API两个版本的对比,绿色为版本更新后新增的内容，红色为删除的内容</p>
<p><img src="img/9.png" /></p>
<h3>3.2.4 @apiGroup API接口的分组</h3>
<p>例如 登录api和获取用户信息api都是用户模块</p>
<pre><code>/**
 * @api {get} /user/:id 
 * @apiGroup User
 */
/**
 * @api {post} /user/login
 * @apiGroup User
 */
</code></pre>

<p>在文档左边菜单栏中，同个模块的api会显示在同一个父标签下，如下图。</p>
<p><img src="img/14.png" /></p>
<h3>3.2.5 @apiParam API的请求参数</h3>
<p>@apiParam [(group)] [{type}] [field=defaultValue] [description]</p>
<table>
<thead>
<tr>
	<th align="center">名称</th>
	<th align="left">含义</th>
</tr>
</thead>
<tbody>
<tr>
	<td align="center">group （可选）</td>
	<td align="left">请求方法的名称DELETE, GET, POST, PUT</td>
</tr>
<tr>
	<td align="center">{type} （可选）</td>
	<td align="left">参数类型{Boolean}, {Number}, {String}, {Object}, {String[]}，<br>(array of strings)</td>
</tr>
<tr>
	<td align="center">{type{size}} （可选）</td>
	<td align="left">变量的范围<br> {string{..5}}这个字符串最多5个字符 <br>{string{2..5}}这个字符串最少2个字符，最多5个字符<br> {number{100-999}} 在100到999之间的数字</td>
</tr>
<tr>
	<td align="center">{type=allowedValues}<br>(可选)</td>
	<td align="left">参数的可选值 <br>{number=1,2,3,99} 这个数字的值只能是其中之一 <br>{string=&quot;small&quot;,&quot;huge&quot;} 这个字符串的值只能是small或者huge <br>{number=1,2,3,99} 这个数字的值只能是其中之一</td>
</tr>
<tr>
	<td align="center">field</td>
	<td align="left">字段名</td>
</tr>
<tr>
	<td align="center">defaultValue</td>
	<td align="left">字段的默认值</td>
</tr>
<tr>
	<td align="center">description</td>
	<td align="left">字段的描述（这个字段的含义）</td>
</tr>
</tbody>
</table>
<h4>Example</h4>
<pre><code>@apiParam {number{number(6,4)}} hertz 对讲频道hertz
@apiParam {String} [firstname]  用户名（非必填）
</code></pre>

<h3>3.2.6 @apiParamExample 请求参数示例</h3>
<p>这个是参数的具体请求格式的一个例子，主要针对json类型的数据，例子如下：</p>
<pre><code>@apiSuccessExample {json} 成功的响应: HTTP 200 OK
     {&quot;state&quot;:0,&quot;value&quot;:{&quot;channelId&quot;:&quot;channel_1&quot;,&quot;channelName&quot;:&quot;华微软件频道一&quot;,&quot;hertz&quot;:90.3456,&quot;description&quot;:&quot;&quot;}}
</code></pre>

<h3>3.2.7 其他</h3>
<h5>@apiError @apiErrorExample 请求出错返回字段说明 请求错误返回数据示例</h5>
<h5>@apiParam @apiParamExample 请求字段说明 请求示例</h5>
<h5>@apiHeader @apiHeaderExample 请求头字段说明 请求头示例</h5>
<h3>以上格式同3.2.5和3.2.6</h3>
<h3>3.2.8 @apiUse 重用的文本模块</h3>
<pre><code>/**
 * @apiDefine MySuccess
 * @apiSuccess {string} firstname The users firstname.
 * @apiSuccess {number} age The users age.
 */

/**
 * @api {get} /user/:id
 * @apiUse MySuccess
 */
</code></pre>

<hr>
<h2>4 生成api文档</h2>
<h3>4.1 项目目录结构</h3>
<ol>
<li>在src目录下，创建apidoc.json文件，是apidoc的项目级配置文件。</li>
<li>apidoc会自动扫描src目录下所有子目录的源文件</li>
</ol>
<h4>Example</h4>
<p>apidoc.json的简单配置</p>
<pre><code>{
  &quot;name&quot;: &quot;demo&quot;, 
  &quot;version&quot;: &quot;1.0.0&quot;,
  &quot;description&quot;: &quot;这是一个简单的apidoc的demo&quot;,
  &quot;title&quot;: &quot;demo&quot;,
  &quot;url&quot; : &quot;https://api.github.com/v1&quot;
}
</code></pre>

<p>可嵌入文档头部和尾部说明，由.md格式文件实现,放在src目录下,补充后的apidoc.json如下</p>
<pre><code>{
    &quot;name&quot;: &quot;approachWarning项目接口文档&quot;,
    &quot;version&quot;: &quot;0.1.0&quot;,
    &quot;description&quot;: &quot;apiDoc-desc&quot;,
    &quot;title&quot;: &quot;approachWarning项目接口文档&quot;,
    &quot;url&quot;: &quot;/ihapi/approachWarning&quot;,
    &quot;header&quot;: {
        &quot;title&quot;: &quot;接口设计&quot;,
        &quot;filename&quot;: &quot;header.md&quot;
    },
    &quot;footer&quot;: {
        &quot;title&quot;: &quot;版本修订历史记录&quot;,
        &quot;filename&quot;: &quot;footer.md&quot;
    }
}   
</code></pre>

<h3>4.2 生成文档</h3>
<p>在命令行窗口中输入 apidoc -i yourSrcPath -o outPutPath 命令</p>
<blockquote>
<p>yourSrcPath：你的项目src目录地址</p>
<p>outPutPath：文档输出地址</p>
</blockquote>
<p>若出现info：Done.结果，则说明文档生成成功。打开index.html即可进入web文档页面</p>
<p><img src="img/10.png" /></p>
<p><img src="img/12.png" /></p>
<h2>5.注意事项</h2>
<h3>1.若加入javadoc注释，必须写在一起，并且javadoc需写在上方</h3>
<p>代码示例</p>
<pre><code>/**
 * 添加或更新应用程序
 * @param appDto 
 * @return
 * 
 * @api {post} /app 3.1.5.添加或更新应用程序
 * @apiGroup Application
 * @apiDescription 添加或更新应用程序
 */
</code></pre>

<h2>6.参考资料</h2>
<p><a href="http://hinylover.space/2016/03/31/create-online-document-use-apidoc/">1.使用apidocJs快速生成在线文档</a></p>
<p><a href="http://apidocjs.com/#param-api-use%E3%80%81">2.apidoc官方文档</a></p>

</body>
</html>
<!-- This document was created with MarkdownPad, the Markdown editor for Windows (http://markdownpad.com) -->
